﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TextCompareTool
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Multiselect = true;//该值确定是否可以选择多个文件
            dialog.Title = "请选择文件夹";
            dialog.Filter = "所有文件(*.*)|*.*";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string file = dialog.FileName;
                textBox1.Text = file;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Multiselect = true;//该值确定是否可以选择多个文件
            dialog.Title = "请选择文件夹";
            dialog.Filter = "所有文件(*.*)|*.*";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string file = dialog.FileName;
                textBox2.Text = file;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox3.Text = "";
            if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text))
            {
                MessageBox.Show("请选择文件！");
                return;
            }
            //读取第一文件内容
            string[] strs1 = File.ReadAllLines(textBox1.Text);
            string[] strs2 = File.ReadAllLines(textBox2.Text);

            if (radioButton1.Checked)
            {
                for (int i = 0; i < strs2.Length; i++)
                {
                    if(string.IsNullOrWhiteSpace(strs2[i].ToString())) continue;
                    if (!strs1.Contains(strs2[i]))
                        textBox3.Text += strs2[i].ToString() + Environment.NewLine;
                }
                
            }
            else if (radioButton2.Checked)
            {
                for (int i = 0; i < strs1.Length; i++)
                {
                    if (string.IsNullOrWhiteSpace(strs1[i].ToString())) continue;
                    if (!strs2.Contains(strs1[i]))
                        textBox3.Text += strs1[i].ToString() + Environment.NewLine;
                }
            }
            else
            {
                for (int i = 0; i < strs2.Length; i++)
                {
                    if (string.IsNullOrWhiteSpace(strs2[i].ToString())) continue;
                    if (!strs1.Contains(strs2[i]))
                        textBox3.Text += strs2[i].ToString() + "\r\n";
                }
                for (int i = 0; i < strs1.Length; i++)
                {
                    if (string.IsNullOrWhiteSpace(strs1[i].ToString())) continue;
                    if (!strs2.Contains(strs1[i]))
                        textBox3.Text += strs1[i].ToString() + Environment.NewLine;
                }

            }
            
        }

        private void button4_Click(object sender, EventArgs e)
        {
            textBox3.Text = @"你好"+Environment.NewLine+"小超超";
        }
    }
}
